package com.renshine.swing.component.panel;

import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.springframework.stereotype.Component;

import com.renshine.base.bean.Assemble;
import com.renshine.base.util.FileUtil;

/**
 * 生成代码面板
 * 
 * @author deyang
 *
 */
@Component
@SuppressWarnings("serial")
public class ButtonPanel extends JPanel {
	private JTextField authorField;
	private JTextField moduleText;
	private JTextField pathText;
	private JComboBox<String> templateBox;
	private JButton sltButton;
	private JButton createButton;

	public ButtonPanel() {
		setBorder(null);
		
		JLabel authorLab = new JLabel("作者");
		JLabel templateLab = new JLabel("模板");
		JLabel moduleLab = new JLabel("模块");
		JLabel pathLab = new JLabel("路径");
		createButton = new JButton("生成代码");
		
		templateBox = new JComboBox<String>(FileUtil.getTemplates());
		templateBox.setPreferredSize(new Dimension(100, 21));
		
		authorField = new JTextField();
		authorField.setPreferredSize(new Dimension(20, 21));
		authorField.setColumns(20);
		
		moduleText = new JTextField();
		moduleText.setColumns(20);
		
		pathText = new JTextField();
		pathText.setColumns(40);
		
		sltButton = new JButton("选择");
		setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5));
		add(authorLab);
		add(authorField);
		add(templateLab);
		add(templateBox);
		add(moduleLab);
		add(moduleText);
		add(pathLab);
		add(pathText);
		
		add(sltButton);
		add(createButton);
	}

	public JTextField getAuthorField() {
		return authorField;
	}

	public void setAuthorField(JTextField authorField) {
		this.authorField = authorField;
	}

	public JTextField getModuleText() {
		return moduleText;
	}

	public void setModuleText(JTextField moduleText) {
		this.moduleText = moduleText;
	}

	public JTextField getPathText() {
		return pathText;
	}

	public void setPathText(JTextField pathText) {
		this.pathText = pathText;
	}

	public JComboBox<String> getTemplateBox() {
		return templateBox;
	}

	public void setTemplateBox(JComboBox<String> templateBox) {
		this.templateBox = templateBox;
	}

	public JButton getSltButton() {
		return sltButton;
	}

	public void setSltButton(JButton sltButton) {
		this.sltButton = sltButton;
	}
	
	public JButton getCreateButton() {
		return createButton;
	}
	
	public void setCreateButton(JButton createButton) {
		this.createButton = createButton;
	}

	public void init(Assemble ab) {
		authorField.setText(ab.getAuthor());
		moduleText.setText(ab.getModule());
		pathText.setText(ab.getCodepath());
		if (ab.getTemplate() != null && !ab.getTemplate().equals("")) {
			templateBox.setSelectedItem(ab.getTemplate());
		}
	}
	
}
